var express = require('express');
var router = express.Router();
var BaseModel = require('../models/base_model');
var baseModel = new BaseModel();
var Q = require('q');


function data1(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data2(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data3(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data4(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data5(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data6(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data7(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};
function data8(data)
{
    var deferred = Q.defer();
    var sql = "select paper_id,aliaspaper from yk_paper where subject_id=" + data + " order by aliaspaper";
    baseModel.findMoreById(sql,function(rett){
        deferred.resolve(rett);
    });
    return deferred.promise;
};

function init(req){
   var deferred = Q.defer();
   if ('undefined' === (typeof req.cookies.ownuser))
   {
       deferred.resolve(null);
   }else{
       deferred.resolve(req.cookies.ownuser);
   }
   return deferred.promise;
};

/* GET home page. */
router.get('/', function(req, res) {
   // Q.all([data1(12),data2(13),data3(14),data4(15),data5(16),data6(17),data7(18),data8(19),init(req)]).spread(function(rs1,rs2,rs3,rs4,rs5,rs6,rs7,rs8,rs9){
      Q.all([data1(12),data2(12),data3(14),data4(12),data5(12),data6(12),data7(12),data8(12),init(req)]).spread(function(rs1,rs2,rs3,rs4,rs5,rs6,rs7,rs8,rs9){
        console.log(rs1);
        console.log(rs2);
        res.render('index', {
           title: '医药考试',
           data1: rs1,
           data2: rs2,
           data3: rs3,
           data4: rs4,
           data5: rs5,
           data6: rs6,
           data7: rs7,
           data8: rs8,
           cook:rs9
        });
    });
});

module.exports = router;
